/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.tech15.pub.model.*;
import com.tech15.pub.dao.*;
import com.tech15.pub.service.*;
import com.tech15.pub.vo.query.*;

/**
 * @author 胡作正 email:zuozhenghu@sina.com
 * @version 1.0
 * @since 1.0
 */


import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

@Repository
public class PubTemplateDao extends BaseHibernateDao<PubTemplate,java.lang.String>{

	public Class getEntityClass() {
		return PubTemplate.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from PubTemplate t where 1=1 "
				+ "/~ and t.name = '[name]' ~/"
				+ "/~ and t.zt = '[zt]' ~/"
				+ "/~ and t.lb = '[lb]' ~/"
				+ "/~ and t.memo = '[memo]' ~/"
				+ "/~ and t.uptime = '[uptime]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(PubTemplateQuery query) {
		String sql = "select t.*,t1.name as dataname,t2.name as categoryName from Pub_Template t " +
					" left join pub_data t1 on t.zt=t1.id " +
					" left join pub_data t2 on t.lb=t2.id where 1=1 "
					+ "/~ and t.name like '%[name]%' ~/"
					+ "/~ and t.zt = [zt] ~/"
					+ "/~ and t.lb = [lb] ~/"
					+ "/~ and t.memo = '[memo]' ~/"
					+ "/~ and t.uptime = '[uptime]' ~/"
					+ "/~ order by [sortColumns] ~/";
		Map map = new HashMap();
		map.put("id","String");
		map.put("name","String");
		map.put("zt","Long");
		map.put("lb","Long");
		map.put("memo", "String");
		map.put("uptime","Timestamp");
		map.put("dataname","String");
		map.put("categoryName","String");
		
		return pageSqlQuery(sql, query, map, PubTemplate.class);
	}
	

}
